package com.ssy.lingxi.member.merchant.entity;

import com.fasterxml.jackson.annotation.JsonBackReference;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;

/**
 * 会员角色当前等级与权益信息表
 * @author 万宁
 * @version 2.0.0
 * @date 2020-07-10
 */
@Entity
@Table(schema = "public", name = "ms_mc_member_level_right", indexes = {@Index(name = "ms_mc_member_level_right_member_role_id_idx", columnList = "memberId, roleId"), @Index(name = "ms_mc_member_level_right_sub_member_role_id_idx", columnList = "subMemberId, subRoleId"), @Index(name = "ms_mc_member_level_right_rel_id_idx", columnList = "rel_id")})
public class MemberLevelRightDO implements Serializable {
    private static final long serialVersionUID = 2001085771908088934L;

    /**
     * 记录id
     */
    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE, generator="member_level_right_seq")
    @SequenceGenerator(sequenceName="ms_mc_member_level_right_seq", name="member_level_right_seq",allocationSize = 1)
    private Long id;

    /**
     * 上级会员Id
     */
    @Column
    private Long memberId;

    /**
     * 上级会员角色Id
     */
    @Column
    private Long roleId;

    /**
     * 下级会员Id
     */
    @Column
    private Long subMemberId;

    /**
     * 下级会员角色Id
     */
    @Column
    private Long subRoleId;

    /**
     * 一对一双向关联会员关系表
     */
    @JsonBackReference
    @OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinColumn(name="rel_id", referencedColumnName="id", foreignKey = @ForeignKey(name = "none",value = ConstraintMode.NO_CONSTRAINT))
    private MemberRelationDO relation;

    /**
     * 当前的等级积分
     */
    @Column(columnDefinition = "int4")
    private Integer score;

    /**
     * 当前等级
     */
    @Column(columnDefinition = "int")
    private Integer level;

    /**
     * 多对一单向关联会员等级配置
     */
    @ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinColumn(name = "member_level_config_id", referencedColumnName = "id")
    private MemberLevelConfigDO levelConfig;

    /**
     * 当前等级标签
     */
    @Column(columnDefinition = "varchar(20)")
    private String levelTag;

    /**
     * 累积返现金额
     */
    @Column(columnDefinition = "numeric")
    private BigDecimal sumReturnMoney;

    /**
     * 累计获得的权益积分
     */
    @Column(columnDefinition = "int")
    private Integer sumPoint;

    /**
     * 当前可用的权益积分 = 累计获得的权益积分 - 累计已用权益积分
     */
    @Column(columnDefinition = "int")
    private Integer currentPoint;

    /**
     * 累计使用的权益积分
     */
    @Column(columnDefinition = "int")
    private Integer sumUsedPoint;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getMemberId() {
        return memberId;
    }

    public void setMemberId(Long memberId) {
        this.memberId = memberId;
    }

    public Long getRoleId() {
        return roleId;
    }

    public void setRoleId(Long roleId) {
        this.roleId = roleId;
    }

    public Long getSubMemberId() {
        return subMemberId;
    }

    public void setSubMemberId(Long subMemberId) {
        this.subMemberId = subMemberId;
    }

    public Long getSubRoleId() {
        return subRoleId;
    }

    public void setSubRoleId(Long subRoleId) {
        this.subRoleId = subRoleId;
    }

    public MemberRelationDO getRelation() {
        return relation;
    }

    public void setRelation(MemberRelationDO relation) {
        this.relation = relation;
    }

    public Integer getScore() {
        return score;
    }

    public void setScore(Integer score) {
        this.score = score;
    }

    public Integer getLevel() {
        return level;
    }

    public void setLevel(Integer level) {
        this.level = level;
    }

    public MemberLevelConfigDO getLevelConfig() {
        return levelConfig;
    }

    public void setLevelConfig(MemberLevelConfigDO levelConfig) {
        this.levelConfig = levelConfig;
    }

    public String getLevelTag() {
        return levelTag;
    }

    public void setLevelTag(String levelTag) {
        this.levelTag = levelTag;
    }

    public BigDecimal getSumReturnMoney() {
        return sumReturnMoney;
    }

    public void setSumReturnMoney(BigDecimal sumReturnMoney) {
        this.sumReturnMoney = sumReturnMoney;
    }

    public Integer getSumPoint() {
        return sumPoint;
    }

    public void setSumPoint(Integer sumPoint) {
        this.sumPoint = sumPoint;
    }

    public Integer getCurrentPoint() {
        return currentPoint;
    }

    public void setCurrentPoint(Integer currentPoint) {
        this.currentPoint = currentPoint;
    }

    public Integer getSumUsedPoint() {
        return sumUsedPoint;
    }

    public void setSumUsedPoint(Integer sumUsedPoint) {
        this.sumUsedPoint = sumUsedPoint;
    }
}
